package com.lagou.edu.controller;

import com.lagou.edu.service.IEmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author stevejson
 */
@Slf4j
@RestController
@RequestMapping("/email")
@RefreshScope
public class EmailController {

    @Resource
    private IEmailService iEmailService;

    @Value("${brushStroke.number}")
    private Integer number;

    @RequestMapping(value = "/{email}/{code}", method = RequestMethod.POST)
    public Boolean sendEmail(@PathVariable String email, @PathVariable String code){
        try {
            iEmailService.sendSimple(email, "验证码", code);
            return true;
        } catch (Exception e){
            log.error("邮件发送失败", e);
            return false;
        }
    }
    @RequestMapping("/number")
    public Integer test(){
        return number;
    }
}
